//
//  UIBarButtonItem+Extention.m
//  025彩票练习2
//
//  Created by 魏云超 on 15/10/28.
//  Copyright (c) 2015年 魏云超. All rights reserved.
//

#import "UIBarButtonItem+Extention.h"

@implementation UIBarButtonItem (Extention)

+(UIBarButtonItem *)itemWithTitle:(NSString *)title norImage:(NSString *)norImage selImage:(NSString *)selImage target:(id)target action:(SEL)action{
    //1.设置按钮
    UIButton *btn = [[UIButton alloc]init];
    //2.设置图片
    if (norImage != nil && ![norImage isEqualToString:@""]) {
        [btn setImage:[UIImage imageNamed:norImage] forState:UIControlStateNormal];
    }
    if (selImage != nil && ![selImage isEqualToString:@""]) {
        [btn setImage:[UIImage imageNamed:selImage] forState:UIControlStateHighlighted];
    }
    
    //设置标题
    [btn setTitle:title forState:UIControlStateNormal];
    //btn.frame = CGRectMake(0, 0, 100, 40);
    //自动调整控件以及子空间frame
    [btn sizeToFit];
    //监听按钮点击事件
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    //创建item
    return  [[UIBarButtonItem alloc]initWithCustomView:btn];
}

@end
